package com.general.framework.wangwenjun;

import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ScheduledExecutorServiceExample1 {
    public static void main(String[] args) {
        ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(2);
        // 1. Runnable
        // ScheduledFuture<?> task = executor.schedule(() -> {
        //     System.out.println("task1 start");
        // }, 2, TimeUnit.SECONDS);
        // 调用cancel之后，任务不会被执行，即使到了2秒之后
        // System.out.println(task.cancel(true));

        // 2. Callable
        ScheduledFuture<Integer> schedule = executor.schedule(() -> 2, 2, TimeUnit.SECONDS);
    }
}
